# -*- coding:utf-8 -*-
__author__ = 'chen_ju0606@163.com'

import os
import configparser
from config.config import INI_PATH

HOT_KEY = 'HOT_KEY'
SYS_SETTING = 'SYS_SETTING'


class ReadConfig:
    """配置文件"""

    def __init__(self):
        if not os.path.exists(INI_PATH):
            raise FileNotFoundError("配置文件%s不存在！" % INI_PATH)
        self.config = configparser.RawConfigParser()  # 当有%的符号时请使用Raw读取
        self.config.read(INI_PATH, encoding='utf-8')

    def _get(self, section, option):
        """获取"""
        return self.config.get(section, option)

    def _set(self, section, option, value):
        """更新"""
        self.config.set(section, option, value)
        with open(INI_PATH, 'w') as f:
            self.config.write(f)

    """获取配置文件中各参数名称"""
    """类方法转换为属性"""

    @property
    def full_screenshot(self):
        return self._get(HOT_KEY, 'FULL_SCREENSHOT')

    @property
    def custom_screenshot(self):
        return self._get(HOT_KEY, 'CUSTOM_SCREENSHOT')

    @property
    def finish(self):
        return self._get(HOT_KEY, 'FINISH')

    @property
    def report(self):
        return self._get(HOT_KEY, 'REPORT')

    @property
    def is_backup_images(self):
        return self._get(SYS_SETTING, 'IS_BACKUP_IMAGES')
    @property
    def case_code_from(self):
        return self._get(SYS_SETTING, 'CASE_CODE_FROM')


ini = ReadConfig()

if __name__ == '__main__':
    pass
